﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：QS_LH_TUIKUANXX实体层次
//********************************************************************************//

#region Entity

using System;
using System.Data;
using Entity;
using Oracle.DataAccess.Client;
using Platform.Configuration;
using Platform.Data;

namespace Entity
{
    [Serializable]
    public class QS_LH_TUIKUANXX
    {
        private decimal? m_dec_i_feetype;

        private decimal? m_dec_i_tktype;

        private decimal? m_dec_i_tuikuanzt;

        private decimal? m_dec_i_ym;

        private decimal m_dec_id;

        private decimal? m_dec_n_ssje;

        private decimal? m_dec_n_tkje;

        private decimal? m_dec_n_ysje;

        private DateTime? m_DT_d_caozuosj;

        private string m_str_s_beizhu;

        private string m_str_s_caozuor;

        private string m_str_s_feiyongbh;

        private string m_str_s_laihanbh;

        private string m_str_s_yonghuh;

        private string m_str_s_yonghum;

        /// <summary>
        /// </summary>
        public decimal ID
        {
            get { return m_dec_id; }
            set { m_dec_id = value; }
        }

        /// <summary>
        /// </summary>
        public string S_LAIHANBH
        {
            get { return m_str_s_laihanbh; }
            set { m_str_s_laihanbh = value; }
        }

        /// <summary>
        ///     用户号
        /// </summary>
        public string S_YONGHUH
        {
            get { return m_str_s_yonghuh; }
            set { m_str_s_yonghuh = value; }
        }

        /// <summary>
        ///     水量年月
        /// </summary>
        public decimal? I_YM
        {
            get { return m_dec_i_ym; }
            set { m_dec_i_ym = value; }
        }

        /// <summary>
        ///     费用编号
        /// </summary>
        public string S_FEIYONGBH
        {
            get { return m_str_s_feiyongbh; }
            set { m_str_s_feiyongbh = value; }
        }

        /// <summary>
        ///     应收金额
        /// </summary>
        public decimal? N_YSJE
        {
            get { return m_dec_n_ysje; }
            set { m_dec_n_ysje = value; }
        }

        /// <summary>
        ///     实收金额
        /// </summary>
        public decimal? N_SSJE
        {
            get { return m_dec_n_ssje; }
            set { m_dec_n_ssje = value; }
        }

        /// <summary>
        ///     退款金额
        /// </summary>
        public decimal? N_TKJE
        {
            get { return m_dec_n_tkje; }
            set { m_dec_n_tkje = value; }
        }

        /// <summary>
        ///     用户名
        /// </summary>
        public string S_YONGHUM
        {
            get { return m_str_s_yonghum; }
            set { m_str_s_yonghum = value; }
        }

        /// <summary>
        ///     费用类型 0:开采井水费 1:加价 3:采灌补收
        /// </summary>
        public decimal? I_FEETYPE
        {
            get { return m_dec_i_feetype; }
            set { m_dec_i_feetype = value; }
        }

        /// <summary>
        ///     退款类型 1:多收退款 2:收错退款 3:调整退款
        /// </summary>
        public decimal? I_TKTYPE
        {
            get { return m_dec_i_tktype; }
            set { m_dec_i_tktype = value; }
        }

        /// <summary>
        /// </summary>
        public string S_CAOZUOR
        {
            get { return m_str_s_caozuor; }
            set { m_str_s_caozuor = value; }
        }

        /// <summary>
        /// </summary>
        public DateTime? D_CAOZUOSJ
        {
            get { return m_DT_d_caozuosj; }
            set { m_DT_d_caozuosj = value; }
        }

        /// <summary>
        ///     1:已确认退款 0:未确认 -1:已退回
        /// </summary>
        public decimal? I_TUIKUANZT
        {
            get { return m_dec_i_tuikuanzt; }
            set { m_dec_i_tuikuanzt = value; }
        }

        /// <summary>
        /// </summary>
        public string S_BEIZHU
        {
            get { return m_str_s_beizhu; }
            set { m_str_s_beizhu = value; }
        }
    }
}

#endregion

#region EntityProcess

namespace BLL.Access
{
    //using System.Data.OracleClient;

    public class QS_LH_TUIKUANXXProcess
    {
        #region Field

        protected string conn;

        #endregion

        #region Construction

        public QS_LH_TUIKUANXXProcess()
        {
            conn = ConfigHelper.PlatformConnString;
        }

        #endregion

        #region public

        /// <summary>
        ///     根据QS_LH_TUIKUANXX实体添加或者修改QS_LH_TUIKUANXX信息
        /// </summary>
        public bool InsertOrUpdate(QS_LH_TUIKUANXX QS_LH_TUIKUANXX, OracleTransaction Transaction)
        {
            if (QS_LH_TUIKUANXX.ID == 0)
                InsertQS_LH_TUIKUANXX(QS_LH_TUIKUANXX, Transaction);
            else
                UpdateQS_LH_TUIKUANXX(QS_LH_TUIKUANXX, Transaction);
            return QS_LH_TUIKUANXX.ID == 0 ? false : true;
        }

        /// <summary>
        ///     根据QS_LH_TUIKUANXX实体添加或修改QS_LH_TUIKUANXX信息
        /// </summary>
        public bool InsertOrUpdate(QS_LH_TUIKUANXX QS_LH_TUIKUANXX)
        {
            return InsertOrUpdate(QS_LH_TUIKUANXX, null);
        }


        /// <summary>
        ///     根据QS_LH_TUIKUANXX主键删除QS_LH_TUIKUANXX信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteQS_LH_TUIKUANXX(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_DelQS_LH_TUIKUANXX";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据QS_LH_TUIKUANXX主键删除QS_LH_TUIKUANXX信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteQS_LH_TUIKUANXX(decimal ID)
        {
            return DeleteQS_LH_TUIKUANXX(ID, null);
        }

        /// <summary>
        ///     根据条件删除QS_LH_TUIKUANXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteQS_LH_TUIKUANXXesDynamic(string WhereClause, OracleTransaction Transaction)
        {
            var spName = "CS_DelQS_LH_TUIKUANXXesDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据条件删除QS_LH_TUIKUANXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteQS_LH_TUIKUANXXesDynamic(string WhereClause)
        {
            return DeleteQS_LH_TUIKUANXXesDynamic(WhereClause, null);
        }

        /// <summary>
        ///     根据QS_LH_TUIKUANXX主键选择QS_LH_TUIKUANXX信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>QS_LH_TUIKUANXX信息</returns>
        public QS_LH_TUIKUANXX SelectQS_LH_TUIKUANXX(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_SelQS_LH_TUIKUANXX";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                var QS_LH_TUIKUANXX = PopulateQS_LH_TUIKUANXX(rd);
                rd.Close();
                return QS_LH_TUIKUANXX;
            }
            return null;
        }

        /// <summary>
        ///     根据QS_LH_TUIKUANXX主键选择QS_LH_TUIKUANXX信息
        /// </summary>
        /// <returns>QS_LH_TUIKUANXX信息</returns>
        public QS_LH_TUIKUANXX SelectQS_LH_TUIKUANXX(decimal ID)
        {
            return SelectQS_LH_TUIKUANXX(ID, null);
        }

        /// <summary>
        ///     选择所有QS_LH_TUIKUANXX信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有QS_LH_TUIKUANXX信息</returns>
        public DataTable SelectQS_LH_TUIKUANXXesAll(OracleTransaction Transaction)
        {
            var spName = "CS_SelQS_LH_TUIKUANXXesAll";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }

        /// <summary>
        ///     选择所有QS_LH_TUIKUANXX信息
        /// </summary>
        /// <returns>所有QS_LH_TUIKUANXX信息</returns>
        public DataTable SelectQS_LH_TUIKUANXXesAll()
        {
            return SelectQS_LH_TUIKUANXXesAll(null);
        }

        /// <summary>
        ///     根据条件选择QS_LH_TUIKUANXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>QS_LH_TUIKUANXX信息</returns>
        public DataTable SelectQS_LH_TUIKUANXXesDynamic(string WhereClause, string OrderByExpression,
            OracleTransaction Transaction)
        {
            var spName = "CS_SelQS_LH_TUIKUANXXesDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择QS_LH_TUIKUANXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>QS_LH_TUIKUANXX信息</returns>
        public DataTable SelectQS_LH_TUIKUANXXesDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectQS_LH_TUIKUANXXesDynamic(WhereClause, OrderByExpression, null);
        }


        /// <summary>
        ///     根据条件选择QS_LH_TUIKUANXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>QS_LH_TUIKUANXX信息</returns>
        public DataTable SelectQS_LH_TUIKUANXXesDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize, OracleTransaction Transaction)
        {
            var spName = "CS_SelQS_LH_TUIKUANXXesDynPaged";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择QS_LH_TUIKUANXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>QS_LH_TUIKUANXX信息</returns>
        public DataTable SelectQS_LH_TUIKUANXXesDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize)
        {
            return SelectQS_LH_TUIKUANXXesDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///     根据条件更新QS_LH_TUIKUANXX字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateQS_LH_TUIKUANXXesDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            var result = 0;
            if (UpdateValue == "" || WhereClause == "")
                return 0;
            var spName = "CS_UpdQS_LH_TUIKUANXXDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///     根据条件更新QS_LH_TUIKUANXX字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateQS_LH_TUIKUANXXesDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateQS_LH_TUIKUANXXesDynamic(UpdateValue, WhereClause, null);
        }

        #endregion

        #region Private

        private int InsertQS_LH_TUIKUANXX(QS_LH_TUIKUANXX QS_LH_TUIKUANXX, OracleTransaction Transaction)
        {
            var spName = "CS_InsQS_LH_TUIKUANXX";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = QS_LH_TUIKUANXX.S_LAIHANBH;
            storedParams[1].Value = QS_LH_TUIKUANXX.S_YONGHUH;
            storedParams[2].Value = QS_LH_TUIKUANXX.I_YM;
            storedParams[3].Value = QS_LH_TUIKUANXX.S_FEIYONGBH;
            storedParams[4].Value = QS_LH_TUIKUANXX.N_YSJE;
            storedParams[5].Value = QS_LH_TUIKUANXX.N_SSJE;
            storedParams[6].Value = QS_LH_TUIKUANXX.N_TKJE;
            storedParams[7].Value = QS_LH_TUIKUANXX.S_YONGHUM;
            storedParams[8].Value = QS_LH_TUIKUANXX.I_FEETYPE;
            storedParams[9].Value = QS_LH_TUIKUANXX.I_TKTYPE;
            storedParams[10].Value = QS_LH_TUIKUANXX.S_CAOZUOR;
            storedParams[11].Value = QS_LH_TUIKUANXX.D_CAOZUOSJ;
            storedParams[12].Value = QS_LH_TUIKUANXX.I_TUIKUANZT;
            storedParams[13].Value = QS_LH_TUIKUANXX.S_BEIZHU;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            QS_LH_TUIKUANXX.ID = Convert.ToInt32(storedParams[14].Value);
            return result;
        }

        private bool UpdateQS_LH_TUIKUANXX(QS_LH_TUIKUANXX QS_LH_TUIKUANXX, OracleTransaction Transaction)
        {
            var spName = "CS_UpdQS_LH_TUIKUANXX";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = QS_LH_TUIKUANXX.S_LAIHANBH;
            storedParams[1].Value = QS_LH_TUIKUANXX.S_YONGHUH;
            storedParams[2].Value = QS_LH_TUIKUANXX.I_YM;
            storedParams[3].Value = QS_LH_TUIKUANXX.S_FEIYONGBH;
            storedParams[4].Value = QS_LH_TUIKUANXX.N_YSJE;
            storedParams[5].Value = QS_LH_TUIKUANXX.N_SSJE;
            storedParams[6].Value = QS_LH_TUIKUANXX.N_TKJE;
            storedParams[7].Value = QS_LH_TUIKUANXX.S_YONGHUM;
            storedParams[8].Value = QS_LH_TUIKUANXX.I_FEETYPE;
            storedParams[9].Value = QS_LH_TUIKUANXX.I_TKTYPE;
            storedParams[10].Value = QS_LH_TUIKUANXX.S_CAOZUOR;
            storedParams[11].Value = QS_LH_TUIKUANXX.D_CAOZUOSJ;
            storedParams[12].Value = QS_LH_TUIKUANXX.I_TUIKUANZT;
            storedParams[13].Value = QS_LH_TUIKUANXX.S_BEIZHU;
            storedParams[14].Value = QS_LH_TUIKUANXX.ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private QS_LH_TUIKUANXX PopulateQS_LH_TUIKUANXX(IDataReader dr)
        {
            var QS_LH_TUIKUANXX = new QS_LH_TUIKUANXX();
            QS_LH_TUIKUANXX.ID = dr["ID"] == DBNull.Value ? 0 : (decimal) dr["ID"];
            QS_LH_TUIKUANXX.S_LAIHANBH = dr["S_LAIHANBH"] == DBNull.Value ? null : (string) dr["S_LAIHANBH"];
            QS_LH_TUIKUANXX.S_YONGHUH = dr["S_YONGHUH"] == DBNull.Value ? null : (string) dr["S_YONGHUH"];
            QS_LH_TUIKUANXX.I_YM = dr["I_YM"] == DBNull.Value ? null : (decimal?) dr["I_YM"];
            QS_LH_TUIKUANXX.S_FEIYONGBH = dr["S_FEIYONGBH"] == DBNull.Value ? null : (string) dr["S_FEIYONGBH"];
            QS_LH_TUIKUANXX.N_YSJE = dr["N_YSJE"] == DBNull.Value ? null : (decimal?) dr["N_YSJE"];
            QS_LH_TUIKUANXX.N_SSJE = dr["N_SSJE"] == DBNull.Value ? null : (decimal?) dr["N_SSJE"];
            QS_LH_TUIKUANXX.N_TKJE = dr["N_TKJE"] == DBNull.Value ? null : (decimal?) dr["N_TKJE"];
            QS_LH_TUIKUANXX.S_YONGHUM = dr["S_YONGHUM"] == DBNull.Value ? null : (string) dr["S_YONGHUM"];
            QS_LH_TUIKUANXX.I_FEETYPE = dr["I_FEETYPE"] == DBNull.Value ? null : (decimal?) dr["I_FEETYPE"];
            QS_LH_TUIKUANXX.I_TKTYPE = dr["I_TKTYPE"] == DBNull.Value ? null : (decimal?) dr["I_TKTYPE"];
            QS_LH_TUIKUANXX.S_CAOZUOR = dr["S_CAOZUOR"] == DBNull.Value ? null : (string) dr["S_CAOZUOR"];
            QS_LH_TUIKUANXX.D_CAOZUOSJ = dr["D_CAOZUOSJ"] == DBNull.Value ? null : (DateTime?) dr["D_CAOZUOSJ"];
            QS_LH_TUIKUANXX.I_TUIKUANZT = dr["I_TUIKUANZT"] == DBNull.Value ? null : (decimal?) dr["I_TUIKUANZT"];
            QS_LH_TUIKUANXX.S_BEIZHU = dr["S_BEIZHU"] == DBNull.Value ? null : (string) dr["S_BEIZHU"];
            return QS_LH_TUIKUANXX;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (var i = 0; i < dt.Rows.Count; i++)
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
        }

        #endregion
    }
}

#endregion